package com.itheima.api;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mapper.CmsSubjectMapper;
import com.itheima.pojo.CmsSubject;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 袁鹏
 * @date 2022-10-14-8:30
 */
@DubboService
public class CmsSubjectApiImpl implements CmsSubjectApi{

    @Autowired
    private CmsSubjectMapper cmsSubjectMapper;


    /**
     * 根据专题名称分页获取商品专题
     */
    @Override
    public Page<CmsSubject> page(String keyword, Integer pageNum, Integer pageSize) {
        Page<CmsSubject> pageInfo = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<CmsSubject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(keyword), CmsSubject::getCategoryName, keyword);
        return cmsSubjectMapper.selectPage(pageInfo, queryWrapper);
    }


    /**
     * 获取全部商品专题
     */
    @Override
    public List<CmsSubject> listAll() {
        return cmsSubjectMapper.selectList(null);
    }
}
